//
//  CardPayView.m
//  项目三
//
//  Created by rimi on 15/10/9.
//  Copyright (c) 2015年 rimi. All rights reserved.
//

#import "CardPayView.h"
#import "TicketView.h"
#import "LicenceView.h"
#import "NumberView.h"
#import "ControllerManager.h"

@interface CardPayView()

@property(nonatomic, strong) UIImageView *backgroundImage;
@property (nonatomic, strong) UIButton *ticketBtn; /**< 按罚单查询 */
@property (nonatomic, strong) UIButton *licenceBtn; /**< 按牌照查询 */
@property (nonatomic, strong) UIButton *numberBtn; /**< 按驾档编号查询 */


- (void)initializeAppearence;
@end

@implementation CardPayView

#pragma mark - init
- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeAppearence];
    }
    return self;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        [self initializeAppearence];
    }
    return self;
}

- (void)initializeAppearence {

    self.backgroundColor = COLOR(205, 205, 205, 1);
    
    [self addSubview:self.backgroundImage];
    [self addSubview:self.ticketBtn];
    [self addSubview:self.licenceBtn];
    [self addSubview:self.numberBtn];
}
#pragma mark - action on btn
- (void)actionOnTicketBtn {

//    [self removeView:self];
    
    [UIView animateWithDuration:1.0 animations:^{
        self.ticketView.alpha = 1;
        
    }];

    [[ControllerManager sharedManager].mainViewController.currentVc.view addSubview:self.ticketView];
    
    
}
- (void)actionOnLicenceBtn {

//    [self removeView:self];
    [UIView animateWithDuration:1.0 animations:^{
        self.licenceView.alpha = 1;
    }];
    [[ControllerManager sharedManager].mainViewController.currentVc.view addSubview:self.licenceView];
}
- (void)actionOnNumberBtn {

//    [self removeView:self];
    [UIView animateWithDuration:1.0 animations:^{
        self.numberView.alpha = 1;
    }];
    [[ControllerManager sharedManager].mainViewController.currentVc.view addSubview:self.numberView];
}
#pragma mark - private method
- (void)removeView:(UIView *)view {
    
    [UIView animateWithDuration:0.6 animations:^{
        view.alpha = 0;
    } completion:^(BOOL finished) {
        
    }];
}

#pragma mark - getter
- (UIImageView *)backgroundImage {

    if (!_backgroundImage) {
        _backgroundImage = ({
        
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
            imageView.image = [UIImage imageNamed:@"灰色背景"];
            
            imageView;
        });
    }
    return _backgroundImage;
}
- (UIButton *)ticketBtn {

    if (!_ticketBtn) {
        _ticketBtn = ({
        
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(200, 138, 333, 125))];
            [button setImage:[UIImage imageNamed:@"按罚单查询1"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnTicketBtn) forControlEvents:UIControlEventTouchUpInside];
            button;
        });
    }
    return _ticketBtn;
}
- (UIButton *)licenceBtn {

    if (!_licenceBtn) {
        _licenceBtn = ({
        
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(200, 138 + 35 + 125, 333, 125))];
            [button setImage:[UIImage imageNamed:@"按牌照查询1"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnLicenceBtn) forControlEvents:UIControlEventTouchUpInside];
            
            button;

        });
    }
    return _licenceBtn;
}
- (UIButton *)numberBtn {

    if (!_numberBtn) {
        _numberBtn = ({
        
            UIButton *button = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(200, 138 + 70 + 250, 333, 125))];
            [button setImage:[UIImage imageNamed:@"按驾档编号查询1"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(actionOnNumberBtn) forControlEvents:UIControlEventTouchUpInside];
            
            button;

        });
    }
    return _numberBtn;
}
- (TicketView *)ticketView {

    if (!_ticketView) {
        _ticketView = ({
        
            TicketView *view = [[TicketView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 82, 708, 944))];
            view.alpha = 0;
            
            view;
        });
    }
    return _ticketView;
}
- (LicenceView *)licenceView {

    if (!_licenceView) {
        _licenceView = ({
        
            LicenceView *view = [[LicenceView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 82, 708, 944))];
            view.alpha = 0;
            view;
        });
    }
    return _licenceView;
}
- (NumberView *)numberView {

    if (!_numberView) {
        _numberView = ({
        
            NumberView *view = [[NumberView alloc]initWithFrame:DHFlexibleFrame(CGRectMake(0, 82, 708, 944))];
            view.alpha = 0;
            view;
        });
    }
    return _numberView;
}
@end
